// // pages/My/Index.js
import{ request }from"../request/index.js";
//点赞功能实现
const TEXT = ['🤣', '👍', '😂', '👏', '😆', '💋', '🎁', '🧑', '🎉', '🎇', '🎋', '🎍', '🧧', '⚽', '🍔', '🍿', '🌰','❤']
let num = 0

Page({
    data: {
        list: [],
        userInfo:[],
        title:[
          {
            user_id:"1",
            likes:"1"
          }
        ],

    },
    //关注
    getUserInfo(e){
      let index = e.currentTarget.dataset.index
      let that = this
      let likes = e.currentTarget.dataset.likes
      let titles = this.data.title
      if (likes==1){
        titles[index].likes = '0'
        that.setData({
          title: titles
        })
        console.log(e.currentTarget.dataset.index,"关注了")
      }else{
        titles[index].likes = 1
        that.setData({
          title: titles
        })
        console.log(e.currentTarget.dataset.index, "取关了")
      }
    },
    //渲染页面数据
    onLoad(){
      const res=request({url: 'http://localhost:35043/api/User/GetIndex'});
      console.log(res);
      this.setData({
        userInfo:res.data
      })
    },
    //点赞
    handlerAdd() {
        num += 1
        let key = `item${num}`
        const index = Math.ceil(Math.random() * TEXT.length) - 1
        let list = JSON.parse(JSON.stringify(this.data.list))
        list.push({text: TEXT[index], id: key})
	// 数组长度阈值，超过此阈值直接改变长度，避免卡顿
        let max = 100
        if (list.length === max) {
            list.reverse()
            list.length = list.length - (max - 70)
            list.reverse()
        }
        this.setData({
            list
        })
    },
    // //关注
    // follow(){
    //   wx.showToast({
    //     title: '已关注',
    //   })
    // },
    // onChange(event) {
    //   wx.showToast({
    //     title: '已关注',
    //   })
    // },
})

